home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / addr / ap_s2t.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.4 KB  |  89 lines

  1. /* ap_s2t.c: convert a string into an address tree */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_s2t.c,v 6.0 1991/12/18 20:21:24 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/addr/RCS/ap_s2t.c,v 6.0 1991/12/18 20:21:24 jpo Rel $
  9.  *
  10.  * $Log: ap_s2t.c,v $
  11.  * Revision 6.0  1991/12/18  20:21:24  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "ap.h"
  20.  
  21.  
  22. static char *ap_str_ptr;
  23.  
  24.  
  25.  
  26.  
  27. /* ---------------------  Static  Routines  ------------------------------- */
  28.  
  29.  
  30.  
  31. static int get_a_char()        /* -- get next character from string -- */
  32. {
  33.  
  34.     if (*ap_str_ptr == '\0')
  35.         /* -- end of the string -- */
  36.         return (-1);
  37.  
  38.     return (*ap_str_ptr++);
  39. }
  40.  
  41.  
  42.  
  43.  
  44. /* ---------------------  Begin  Routines  -------------------------------- */
  45.  
  46.  
  47.  
  48. /* -- parse a string into an address tree -- */
  49.  
  50. AP_ptr ap_s2t (thestr)
  51. char            *thestr;
  52. {
  53.     int     got_one;
  54.     AP_ptr  thetree;
  55.  
  56.  
  57.     PP_DBG (("Lib/addr/ap_s2t (%s)", thestr));
  58.  
  59.     ap_str_ptr = thestr;
  60.  
  61.     if ((thetree = ap_pinit (get_a_char)) == BADAP)
  62.         return( NULLAP);
  63.  
  64.     ap_clear();
  65.  
  66.     got_one = 0;
  67.  
  68.     for (;;)
  69.         switch (ap_1adr()) {
  70.         case NOTOK:
  71.             (void) ap_sqdelete (thetree, NULLAP);
  72.             ap_free (thetree);
  73.             return (NULLAP);
  74.  
  75.         case OK:
  76.             /* -- more to process -- */
  77.             got_one++;
  78.             continue;
  79.  
  80.         case DONE:
  81.             if (got_one != 1){
  82.                 (void) ap_sqdelete(thetree, NULLAP);
  83.                 ap_free(thetree);
  84.                 thetree = BADAP;
  85.             }
  86.             return (thetree);
  87.         }
  88. }
  89.